<script setup>
import { ref } from 'vue'
import { login, JumpUrl } from '@/api/login'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
const router = useRouter()
const form = ref({
  username: '18000000000',
  password: 'qwer1234'
})
const onSubmit = () => {
  login(form.value).then(res => {
    if (res.list.length > 0 && res.list.length == 1) {
      JumpUrl(res.list[0].id).then(res => {
        ElMessage({
          message: res.msg,
          type: 'success',
        })
      })
      router.push('/')
    } else if (res.list.length > 1) {
      localStorage.setItem('login_info', JSON.stringify(res.list))
    } else {
      ElMessage({
        message: '该用户没有可登录角色',
        type: 'error',
      })
    }
  });

}

</script>
<template>
  <div class="box">
    <el-form :model="form" >
      <el-form-item label="账号">
        <el-input v-model="form.username" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" style="width: 100%">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<style scoped>
.box {
  width: 700px;
  height: 350px;
  background-color: #ccc;
  margin: auto;
  padding: 20px;
}
</style>
